/**
 * Copyright (c) Software Institude of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.model.uml.Kernel;
// imports:
import org.w3c.dom.Element;

import edu.pku.sei.gefcommon.descriptor.annotation.ListProperty;
import edu.pku.sei.gefcommon.descriptor.annotation.MethodProperty;
import edu.pku.sei.modeler.model.common.MetaTypedList;
import edu.pku.sei.modeler.model.uml.Dependencies.Dependency;
import edu.pku.sei.modeler.model.xml.XMLUtility;
import edu.pku.sei.modeler.uml.modelHelper.ModelPackage;
import edu.pku.sei.modeler.uml.util.MetaTypedSet;



/**
 * @generated
 * modified by zsj
 */
public class Comment extends UMLElement implements IComment {
	// attributes
	
	protected String body = "comment";
	
	
	
	
	// references
	
	protected MetaTypedList annotatedElement;
	
	
//	 added by zsj to create fake model for comment link
	private MetaTypedList commentLink;

	// end of adding
	
	
	
	// getters & setters for attributes
	
	@MethodProperty(
			id = "COMMENT_BODY",
			catalog = "General",
			name = ModelPackage.COMMENT_BODY,
			setter = "setBody"
			)
	
	public String getBody() {
		return body;
	}
	public void setBody(String newBody) {
		String oldbody = body;
		body = newBody;
		firePropertyChange(ModelPackage.COMMENT_BODY, oldbody, newBody);
	}
	
	// getters for references
	@MethodProperty(id = "COMMENT_ANNOTATEDELEMENT", catalog = "Reference", name = ModelPackage.COMMENT_ANNOTATEDELEMENT)
	@ListProperty(allowTypes = { UMLElement.class }, newInstanceMethod = "newInstance", typeString = ModelPackage.__UMLELEMENT__)
	public MetaTypedList getAnnotatedElement() {
		if(annotatedElement == null) {
			annotatedElement = new MetaTypedSet(UMLElement.class, this, ModelPackage.COMMENT_ANNOTATEDELEMENT);
		}
		return annotatedElement;
	}
	
	public MetaTypedList getCommentLink() {
		if (this.commentLink == null) {
			commentLink = new MetaTypedSet(Dependency.class,this, ModelPackage.COMMENT_LINK);
		}
		
		return commentLink;
	}
	
	
	// save & load
	public void serialize(Element root) {
		super.serialize(root);
		// attributes
		
		XMLUtility.xmlInstance.serializeAttribute(root, ModelPackage.COMMENT_BODY, body);
		
		// references
		
		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.COMMENT_ANNOTATEDELEMENT, annotatedElement);		
		
		XMLUtility.xmlInstance.serializeNodes(root, ModelPackage.COMMENT_LINK, this.commentLink);
	
	}
	
	public void deSerialize(Element root) {
		super.deSerialize(root);
		// attributes
		
		body = XMLUtility.xmlInstance.deSerializeString(root, ModelPackage.COMMENT_BODY);
		
		// references
		
		this.getAnnotatedElement().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.COMMENT_ANNOTATEDELEMENT, this));
		
		this.getCommentLink().addAll(XMLUtility.xmlInstance.deSerializeNodes(root, ModelPackage.COMMENT_LINK));
	
	}
	
	public void dynamicSet(String featureID, Object value) {
		if(featureID == null || "".equals(featureID)) {
			return;
		}
		// attributes
		
		// references
		else if (ModelPackage.COMMENT_LINK.equals(featureID)) {
			this.getCommentLink().add(value);
		}
		else if(ModelPackage.COMMENT_ANNOTATEDELEMENT.equals(featureID)) {
			getAnnotatedElement().add(value);
		}
		
		else
			super.dynamicSet(featureID, value);
	}
}
 
 
 
 
 